# Config file for @PROJECT_NAME_LOWER@
#
# It defines the following variables:
#
# @PROJECT_NAME_UPPER@_INCLUDE_DIRS     - include directory
# @PROJECT_NAME_UPPER@_LIBRARIES        - all dynamic libraries
# @PROJECT_NAME_UPPER@_STATIC_LIBRARIES - all static libraries

@PACKAGE_INIT@

set_and_check(@PROJECT_NAME_UPPER@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

### Resolve Genicam first
function(resolve_genicam)
  set_and_check(GENICAM_INCLUDE_DIR "@PACKAGE_GENICAM_INSTALL_INCLUDEDIRS@")
  set_and_check(GENICAM_LIBRARY_DIR "@PACKAGE_GENICAM_INSTALL_LIBDIRS@")

  list(APPEND @PROJECT_NAME_UPPER@_INCLUDE_DIRS "${GENICAM_INCLUDE_DIR}")
  set(@PROJECT_NAME_UPPER@_INCLUDE_DIRS "${@PROJECT_NAME_UPPER@_INCLUDE_DIRS}" PARENT_SCOPE)

  if (UNIX)
    # try to get architecture from compiler
    EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine COMMAND tr -d '\n' OUTPUT_VARIABLE CXX_MACHINE)
    string(REGEX REPLACE "([a-zA-Z_0-9]+).*" "\\1" ARCHITECTURE ${CXX_MACHINE})
  elseif (WIN32)
    if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
      set(ARCHITECTURE WIN32_i86)
    else ()
      set(ARCHITECTURE WIN64_x64)
    endif ()
  endif ()

  message(STATUS "Detected architecture ${ARCHITECTURE}")

  set(GENICAM_LIB_SUFFIX)
  if ("${ARCHITECTURE}" STREQUAL "arm")
    set(GENICAM_LIB_SUFFIX ".so")
  elseif ("${ARCHITECTURE}" STREQUAL "aarch64")
    set(GENICAM_LIB_SUFFIX ".so")
  elseif ("${ARCHITECTURE}" STREQUAL "i686")
    set(GENICAM_LIB_SUFFIX ".so")
  elseif ("${ARCHITECTURE}" STREQUAL "x86_64")
    set(GENICAM_LIB_SUFFIX ".so")
  elseif ("${ARCHITECTURE}" STREQUAL "WIN32_i86")
    set(GENICAM_LIB_SUFFIX ".lib")
  elseif ("${ARCHITECTURE}" STREQUAL "WIN64_x64")
    set(GENICAM_LIB_SUFFIX ".lib")
  else ()
    message(FATAL_ERROR "Unknown architecture")
  endif ()

  foreach(GENICAM_LIB @Genicam_TARGETS@)
    add_library(${GENICAM_LIB} SHARED IMPORTED)
    set_property(TARGET ${GENICAM_LIB} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
    set_property(TARGET ${GENICAM_LIB} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)

    string(REPLACE "genicam::" "" GENICAM_LIB_NAME ${GENICAM_LIB})
    set(GENICAM_LIB_FILE "${GENICAM_LIBRARY_DIR}/${GENICAM_LIB_NAME}${GENICAM_LIB_SUFFIX}")

    list(APPEND @PROJECT_NAME_UPPER@_LIBRARIES "${GENICAM_LIB_FILE}")
    set(@PROJECT_NAME_UPPER@_LIBRARIES "${@PROJECT_NAME_UPPER@_LIBRARIES}" PARENT_SCOPE)

    if (UNIX)
      set_target_properties(${GENICAM_LIB}
         PROPERTIES
           INTERFACE_INCLUDE_DIRECTORIES "${GENICAM_INCLUDE_DIR}"
           IMPORTED_LOCATION_DEBUG "${GENICAM_LIB_FILE}"
           IMPORTED_LOCATION_RELEASE "${GENICAM_LIB_FILE}"
           IMPORTED_LOCATION "${GENICAM_LIB_FILE}")
    elseif (WIN32)
      set_target_properties(${GENICAM_LIB}
        PROPERTIES
          INTERFACE_INCLUDE_DIRECTORIES "${GENICAM_INCLUDE_DIR}"
          IMPORTED_IMPLIB_DEBUG  "${GENICAM_LIB_FILE}"
          IMPORTED_IMPLIB_RELEASE "${GENICAM_LIB_FILE}"
          IMPORTED_IMPLIB "${GENICAM_LIB_FILE}")
    endif ()
  endforeach()
endfunction(resolve_genicam)

resolve_genicam()

## Targets
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME_UPPER@Targets.cmake")

set(@PROJECT_NAME_UPPER@_STATIC_LIBRARIES @PROJECT_STATIC_LIBRARIES@)
list(APPEND @PROJECT_NAME_UPPER@_LIBRARIES @PROJECT_LIBRARIES@)

